package com.tn.task;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tn.dao.external.subsystem.IGateTruckDao;

import com.tn.dao.mbpdao.TaskInfoDispatch;
import com.tn.taskdispatch.TaskInfoDispatchService;
import com.tn.utils.JsonUtil;
import com.tn.utils.redis.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Component
@Slf4j
public class SqlTask {



    @Autowired
    private IGateTruckDao iGateDao;

    @Autowired
    private TaskInfoDispatchService taskInfoDispatchService;

    @Scheduled(cron = "0/5 * * * * ?")
    public void executeSqlTask(){

        //查询铲车对应的任务货品信息
        QueryWrapper<TaskInfoDispatch> wrapper=new QueryWrapper<>();
        List<Integer> list=new ArrayList<>();
        list.add(3);
        wrapper.notIn("status",list);
        wrapper.orderByDesc("create_time");
        List<TaskInfoDispatch> taskInfoDispatches = taskInfoDispatchService.getBaseMapper().selectList(wrapper);
        Map<String, List<TaskInfoDispatch>> collect = taskInfoDispatches.stream().collect(Collectors.groupingBy(TaskInfoDispatch::getGpsCard));
        String s = JsonUtil.obj2String(collect);
        RedisUtils.setCacheObject("loader_car_task",s);
        //Variable.taskInfoDispatches=collect;
        List<Map<String, String>> maps = iGateDao.selectAllTruckTag();
        String s1 = JsonUtil.obj2String(maps);
        RedisUtils.setCacheObject("truck_tag",s1);


    }
}
